package com.shujia.flink.window

import org.apache.flink.streaming.api.scala._

object Demo3CountWindow {
  def main(args: Array[String]): Unit = {

    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val lineDS: DataStream[String] = env.socketTextStream("master", 8888)

    val kvDS: DataStream[(String, Int)] = lineDS
      .flatMap(_.split(","))
      .map((_, 1))

    /**
      * 滑动
      * 滚动
      *
      */

    kvDS
      .keyBy(_._1)
      .countWindow(10, 2)
      .sum(1)
      .print()

    env.execute()
  }
}
